<?php

/**
 * This is the model class for table "raids".
 *
 * The followings are the available columns in table 'raids':
 * @property string $id
 * @property string $pool_id
 * @property string $name
 * @property string $raid_value
 * @property string $color
 * @property string $image_url
 * @property integer $hidden
 *
 * The followings are the available model relations:
 * @property Events[] $events
 * @property Items[] $items
 * @property Pools $pool
 */
class Raids extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Raids the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'raids';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('pool_id, name', 'required'),
			array('hidden', 'numerical', 'integerOnly'=>true),
			array('pool_id', 'length', 'max'=>10),
			array('name', 'length', 'max'=>128),
			array('raid_value', 'length', 'max'=>11),
			array('color', 'length', 'max'=>6),
			array('image_url', 'length', 'max'=>256),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, pool_id, name, raid_value, color, image_url, hidden', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'events' => array(self::HAS_MANY, 'Events', 'raid_id'),
			'items' => array(self::HAS_MANY, 'Items', 'raid_id'),
			'pool' => array(self::BELONGS_TO, 'Pools', 'pool_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'pool_id' => 'Pool',
			'name' => 'Name',
			'raid_value' => 'Raid Value',
			'color' => 'Color',
			'image_url' => 'Image Url',
			'hidden' => 'Hidden',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('pool_id',$this->pool_id,true);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('raid_value',$this->raid_value,true);
		$criteria->compare('color',$this->color,true);
		$criteria->compare('image_url',$this->image_url,true);
		$criteria->compare('hidden',$this->hidden);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}